#include<stdio.h>
int main()
{
    int num[105][105] = {0};
    //freopen("in.txt","r",stdin);
    int r,c;
    scanf("%d %d",&r,&c);
    for(int i = 0; i < r; i++)
    {
        for(int j = 0; j < c; j++)
        {
            scanf("%d",&num[i][j]);
            num[i][c] += num[i][j];
            num[r][j] += num[i][j];
            num[r][c] += num[i][j];
        }
    }
    for(int i = 0; i <= r; i++)
    {
        for(int j = 0; j <= c; j++)
        {
            printf("%d ",num[i][j]);
        }
        printf("\n");
    }
}